import Vue from "vue";

import axios from 'axios'

import Vuex from 'vuex';

Vue.use(Vuex);

const state ={
    count : 0 ,
    movieList : []
};

const mutations = {
    add(state){
        state.count ++ ;
    },
    addN(state,{n}){
        state.count += n ;
    },
    setMovieList(state,movie){
        state.movieList = movie
    }
};

const actions = {
    async getMovieListHandel({commit}){
        const re = await axios.get("https://pcw-api.iqiyi.com/search/recommend/list?channel_id=1&data_type=1&mode=11&page_id=2&ret_num=48&session=b9fd987164f6aa47fad266f57dffaa6a")
        commit("setMovieList" ,re.data.data.list)
    }
};

const getters={
    myMovieList(state){
        return state.movieList.filter(item =>{
            return item.albumName.length < 7 && item.albumName.length > 3
         })
    },
    parameterMovie(){
        return ({stare , end}) =>{
            return state.movieList.filter(item =>{
                return item.albumName.length < end && item.albumName.length > stare
             })
        }
    }
}



export default new Vuex.Store({
    state,
    mutations,
    actions,
    getters
})